package cn.net.sdjx.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.net.sdjx.common.Pagination;
import cn.net.sdjx.dao.WaiterMapper;
import cn.net.sdjx.param.WaiterParam;
import cn.net.sdjx.pojo.Waiter;
import cn.net.sdjx.service.WaiterService;
@Service("waiterService")
public class WaiterServiceImpl implements WaiterService {
	@Autowired
	WaiterMapper waiterMapper;
	@Override
	public List<Waiter> javaPoi() throws IOException {
		return null;
	}

	@Override
	public List<Waiter> readXls() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getValue(HSSFCell hssfCell) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int insertSelective(Waiter record) {
		
		return waiterMapper.insertSelective(record);
	}


	@Override
	public int getTotalCount(WaiterParam params) {
		
		return waiterMapper.getTotalCount(params);
	}

	@Override
	public Pagination<Waiter> getPageList(WaiterParam params) {
		Pagination<Waiter> pageList = new Pagination<Waiter>();
		int totalCount = waiterMapper.getTotalCount(params);
		pageList.setNumPerPage(params.getNumPerPage());
		pageList.setTotalCount(totalCount);
		pageList.setPageNum(params.getPageNum());
		if(pageList.getPageNum()>pageList.getTotalPage()){
			pageList.setPageNum(pageList.getTotalPage());
		}
		if (totalCount == 0) {
			pageList.setResult(new ArrayList<Waiter>());
		} else {
			pageList.setResult(waiterMapper.getPageList(params));
		}
		pageList.setPageNum(params.getPageNum());
		return pageList;
	}

	@Override
	public Waiter selectByPrimaryKey(Integer id) {
		
		return waiterMapper.selectByPrimaryKey(id);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return waiterMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Pagination<WaiterParam> getPage(WaiterParam params) {
		Pagination<WaiterParam> pageList = new Pagination<WaiterParam>();
		int totalCount = waiterMapper.getTotalCount(params);
		pageList.setNumPerPage(params.getNumPerPage());
		pageList.setTotalCount(totalCount);
		pageList.setPageNum(params.getPageNum());
		if(pageList.getPageNum()>pageList.getTotalPage()){
			pageList.setPageNum(pageList.getTotalPage());
		}
		if (totalCount == 0) {
			pageList.setResult(new ArrayList<WaiterParam>());
		} else {
			pageList.setResult(waiterMapper.getPage(params));
		}
		pageList.setPageNum(params.getPageNum());
		return pageList;
	}


	@Override
	public List<Waiter> getByidcard(String idcard) {
		return waiterMapper.getByidcard(idcard);
	}

	@Override
	public boolean delete(){
		return waiterMapper.delete();
	}
	@Override
	public Pagination<WaiterParam> getPagePrinting(WaiterParam params) {
		Pagination<WaiterParam> pageList = new Pagination<WaiterParam>();
		int totalCount = waiterMapper.getTotalCount(params);
		pageList.setNumPerPage(params.getNumPerPage());
		pageList.setTotalCount(totalCount);
		pageList.setPageNum(params.getPageNum());
		if(pageList.getPageNum()>pageList.getTotalPage()){
			pageList.setPageNum(pageList.getTotalPage());
		}
		if (totalCount == 0) {
			pageList.setResult(new ArrayList<WaiterParam>());
		} else {
			pageList.setResult(waiterMapper.getPage(params));
		}
		pageList.setPageNum(params.getPageNum());
		return pageList;
	}

}
